import { createStore } from 'vuex';
const store = createStore({
  state() {
    return {
      logInf: { id: 123123 },
      userInf: {} as any,
    };
  },
  getters: {
    getLogInf(state) {
      return state.logInf;
    },
    getUserInf(state) {
      return state.userInf;
    },
  },
  mutations: {
    setLogInf(state, logInf) {
      state.logInf = logInf;
    },
    setUserInf(state, userInf) {
      state.userInf = userInf;
      if (userInf.is_admin === 1) {
        state.userInf.is_admin = {
          value: "admin",
          name: "管理员",
        };
      } else if (userInf.is_admin === 0) {
        state.userInf.is_admin = {
          value: "user",
          name: "用户",
        };
      }
    },
    logout(state) {
      state.userInf = {};
    },
  },
  actions: {
    setLogInf(context, logInf) {
      context.commit("setLogInf", logInf);
    },
    setUserInf(context, userInf) {
      context.commit("setUserInf", userInf);
    },
    logout(context: any) {
      context.commit("logout");
    },
  },
});
export default store;
